package enums;


import java.util.Random;

enum Game2 {
    rock("石头"), scissors("剪刀"), paper("布");

    private final static Outcome[][] os = new Outcome[][] {
            {Outcome.DRAW, Outcome.WIN, Outcome.LOSE},
            {Outcome.LOSE, Outcome.DRAW, Outcome.WIN},
            {Outcome.WIN, Outcome.LOSE, Outcome.DRAW}
    };

    private String name;
    Game2(String name) {
        this.name = name;
    }

    public Outcome compete(Game2 game) {
        return os[this.ordinal()][game.ordinal()];
    }

    @Override
    public String toString() {
        return this.name;
    }
}

/**
 * 使用二维数组实现石头剪刀布
 */
public class RoShamBo2 {

    private static Game2[] games = Game2.values();
    private static Random random = new Random();

    static Game2 newGame() {
        return games[random.nextInt(games.length)];
    }

    static void play(Game2 g1, Game2 g2) {
        System.out.printf("%-2s vs %-2s  =>  %s\n", g1, g2, g1.compete(g2));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++)
            play(newGame(), newGame());
    }
}
